package com.softwaredesign.springboot.mapper;

import com.softwaredesign.springboot.controller.dto.RoleAuthorityDTO;
import com.softwaredesign.springboot.entity.RoleAuthority;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleAuthorityMapper {

    @Select("select * from role_authority")
    List<RoleAuthorityDTO> findAll();

    @Select("select roleCode from sys_role where id = #{id}")
    Integer findRoleCodeByID(Integer id);

    @Select("select roleName from sys_role where id = #{id}")
    String findRoleNameByID(Integer id);

    @Select("select authorityCode from sys_authority where id = #{id}")
    Integer findAuthorityCodeByID(Integer id);

    @Select("select authorityName from sys_authority where id = #{id}")
    String findAuthorityNameByID(Integer id);

    @Insert("INSERT into role_authority(roleID, authorityID)" +
            " VALUES (#{roleID}, #{authorityID})")
    int insert(RoleAuthorityDTO roleAuthorityDTO);

    @Delete("delete from role_authority where roleID = #{id1} and authorityID = #{id2}")
    Integer deleteById(@Param("id1") Integer id1, @Param("id2") Integer id2);

    @Select("select * from role_authority where roleID = #{roleID}")
    List<RoleAuthorityDTO> selectPage(Integer roleID);
}
